package code.model

import org.squeryl.annotations.Column
import net.liftweb.record.field._
import net.liftweb.record._
import net.liftweb.squerylrecord.KeyedRecord
import net.liftweb.squerylrecord.RecordTypeMode._


class Homepage private() extends Record[Homepage] with KeyedRecord[Long] {
  def meta = Homepage

  @Column(name="id")
  override val idField = new LongField(this)

  @Column(name="prod_id")
  val prodId = new LongField(this)

}

object Homepage extends Homepage with MetaRecord[Homepage] {

  def getAllHomepageProducts: List[Homepage] =
    from(MySchema.homepage)(p => select(p)).toList


  def products =
    from(MySchema.homepage, MySchema.products)((h, p) =>
      where(h.prodId === p.idField)
        select(p)
        orderBy(p.sort asc)
    )
}